#include <QApplication>
#include <QDateTime>
#include <QDebug>
#include <QProcess>
#include <QJsonDocument>
#include <QJsonObject>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QProcess process;
    process.start("docker", QStringList() << "ps" << "-a" << "--format" << "{{json .}}");
    process.waitForFinished();
    while (process.canReadLine()) {
        QString line = process.readLine();
        QJsonDocument doc = QJsonDocument::fromJson(line.toUtf8());
        if (!doc.isObject()) {
            continue;
        }
        
        QJsonObject obj = doc.object();
        
        auto Command = obj.value("Command").toString();
        auto CreatedAt = obj.value("CreatedAt").toString();
        auto ID = obj.value("ID").toString();
        auto Image = obj.value("Image").toString();
        auto Labels = obj.value("Labels").toString();
        auto LocalVolumes = obj.value("LocalVolumes").toString();
        auto Mounts = obj.value("Mounts").toString();
        auto Names = obj.value("Names").toString();
        auto Networks = obj.value("Networks").toString();
        auto Ports = obj.value("Ports").toString();
        auto RunningFor = obj.value("RunningFor").toString();
        auto Size = obj.value("Size").toString();
        auto State = obj.value("State").toString();
        auto Status = obj.value("Status").toString();

        qDebug() << Names << State << Status << Image;
    }

    return 0;
}

/**
{
    "Command": "\"/usr/bin/tini -- /u?\"",
    "CreatedAt": "2025-05-23 00:08:16 +0800 CST",
    "ID": "8954a83591e4",
    "Image": "jenkins/jenkins:lts",
    "Labels": "org.opencontainers.image.licenses=MIT,org.opencontainers.image.revision=2dc434f989966a32739719c8d9bb6c522cc33090,org.opencontainers.image.source=https://github.com/jenkinsci/docker,org.opencontainers.image.title=Official Jenkins Docker image,org.opencontainers.image.url=https://www.jenkins.io/,org.opencontainers.image.vendor=Jenkins project,org.opencontainers.image.version=2.504.1,org.opencontainers.image.description=The Jenkins Continuous Integration and Delivery server",
    "LocalVolumes": "0",
    "Mounts": "/data/jenkins_?",
    "Names": "jenkins",
    "Networks": "bridge",
    "Ports": "0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 50000/tcp, 0.0.0.0:50000->5000/tcp, :::50000->5000/tcp",
    "RunningFor": "2 hours ago",
    "Size": "4.7MB (virtual 470MB)",
    "State": "running",
    "Status": "Up 2 hours"
}
 */